;(function(window) {

    function initPopup() {
        renderPopup()
    }

    function renderPopup() {
        var htmls =[
            '<div class="pop">',
            '<div class="pop_warn">',
            '<h3 id="pop_warn_close">警告<span class="iconfont icon-x close-popup-btn">X</span></h3>',
            '<p id="warning_box_content"></p>',
            '<div class="pop_oper">',
            '<button class="btn btn-info" id="pop_warn_confirm_w">确定</button>',
            '</div>',
            '</div>',
            '<div class="pop_hint">',
            '<h3 id="menu_tishi">提示<span class="iconfont icon-x close-popup-btn">X</span></h3>',
            '<p id="pop_hint_content"></p>',
            '<div class="pop_oper">',
            '<button class="btn btn-info" id="pop_warn_confirm_t">确定</button>',
            '<button class="btn" id="cancel_btn" style="margin-left: 20px;">取消</button>',
            '</div>',
            '</div>',
            '</div>',
        ]
        $('body').append(htmls.join(''))
    }

    /**
     * @description 显示弹窗
     * @param {string} content 弹窗的内容
     * @param {object} payload 确定按钮的属性
     */
    function showHint(content, payload) {
        $('.pop').css({"display": "flex"})
        $('.pop_hint').show()
        $('.pop_warn').hide()
        $("#pop_hint_content").html(content)
        if(payload && Object.prototype.toString.call(payload) === "[object Object]") {
            for (var key in payload) {
                if (Object.hasOwnProperty.call(payload, key)) {
                    var element = payload[key];
                    $("#pop_warn_confirm_t").attr('data-'+key, element)
                }
            }
        }
    }

    /**
     * @description 显示弹窗
     * @param {string} content 弹窗的内容
     */
    function showWarning(content) {
        $('.pop').css({"display": "flex"})
        $('.pop_hint').hide()
        $('.pop_warn').show()
        $("#warning_box_content").html(content)
    }

    // 隐藏弹窗
    function hidePopup() {
        $('.pop').hide()
        $('.pop_hint').hide()
        $('.pop_warn').hide()
        $("#warning_box_content, #pop_hint_content").html('')
        $("#pop_warn_confirm_t").replaceWith('<button class="btn btn-info" id="pop_warn_confirm_t">确定</button>')
        // $("#pop_warn_confirm_w").replaceWith('<button class="btn btn-info" id="pop_warn_confirm_w">确定</button>')
    }

    // 监听关闭弹窗
    $(document).on('click', '#cancel_btn, #pop_warn_confirm_w, .close-popup-btn', function() {
        hidePopup()
    })

    // 监听确认取消框的确定按钮
    $(document).on('click', '#pop_warn_confirm_t', function() {
        handleConfirm($(this))
    })

    function handleConfirm(jqueryDom) {
        var type = jqueryDom.attr("data-type")
        console.log('type :>> ', type);
        if(!type) {
            hidePopup()
        }
        if(type === "deleteSlider") { 
            // OCR -- 删除slider
            var id = jqueryDom.attr("data-id")
            return swiperTools.del(id)
        }
        if(type === "deleteVp") { 
            // 删除敏感词
            // 获取用户名
            var userName = jqueryDom.attr("data-username")
            // 删除声纹
            return hotword.fetchHotwordDel(userName)
        }
        if(type === "deleteFace") { 
            // 删除人脸
            var userId = jqueryDom.attr("data-userId")
            var picId = jqueryDom.attr("data-picId")
            return faceTools.fetchDelete(userId, picId)
        }
    }

    initPopup()
    window.popup = {
        initPopup: initPopup,
        showHint: showHint,
        showWarning: showWarning,
        hidePopup: hidePopup
    }
})(window)